package com.spt.ws.tasks.impl;

import java.util.List;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.spt.core.Property;
import com.spt.core.TaskAnnotation;
import com.spt.ws.client.WebServiceBase;
import com.spt.ws.dao.IClientDao;
import com.spt.ws.tasks.ITask;

@Component(value = "hdltjSendBean")
@TaskAnnotation(job_name = "耗电量统计信息", task_id = "FjjToWy_hdltj", group_id = "fjj_to_wy", cron = "0/4 * * * * ?", autoRun = "N")
public class HdlTjxx extends WebServiceBase implements ITask {
    private static Logger log = LogManager.getLogger("com.spt.ws.client");
    @Autowired
    private IClientDao dao;

    private String head = "#HEAD";
    private String end = "#END";

    @Override
    public void doTask() {
        log.info("start getHDLTJ（耗电量统计信息）..........");
        try {
            List<Map<String, Object>> li = dao.getHDLTJ();
            StringBuffer parm = new StringBuffer(head);
            // String[] keys = new
            // String[]{"SBID","KJSJ","GJSJ","YXSJ","BFJSX","BFJYXXL"};
            String[] keys = Property.getProperty("fjj.send.hdltj").split(",");
            if (li == null || li.size() == 0) {
                log.info("getHDLTJ（耗电量统计信息）no data selected,retrun!");
                return;
            }
            for (Map<String, Object> map : li) {
                parm.append(this.assembleLine(keys, map));
            }
            parm.append(end);
            log.info("getHDLTJ（耗电量统计信息） send msg is : " + parm.toString());
            String res = callWS("getHDLTJ", parm.toString());
            log.info("getHDLTJ（耗电量统计信息） return msg is :" + res);
            if (checkMsg(res)) {
                dao.setHDLTJflag("1");
            } else {
                dao.setHDLTJflag("1");
            }
        } catch (Exception e) {
            log.info("getHDLTJ（耗电量统计信息） error: " + e.getMessage());
        }
        log.info("end getHDLTJ（耗电量统计信息）..........");
    }

}
